package com.ruitu.mall_98_2.mvp.presenter;

import com.beanu.arad.utils.ToastUtils;
import com.ruitu.mall_98_2.mvp.contract.AddAddressContract;
import com.ruitu.router_module.bean.api.BaseResult;
import com.ruitu.router_module.bean.api.SubscriberImpl;

public class AddAddressPresenter extends AddAddressContract.Presenter {
    @Override
    public void addAddress(String userId, String ressName, String province, String city, String county, String address, String postCode, String phoneNumber, String status) {
        mModel.addAddress(userId, ressName, province, city, county, address, postCode, phoneNumber, status)
                .subscribe(new SubscriberImpl<BaseResult>() {
                    @Override
                    public void onError(Throwable e) {
                        mView.hideProgress();
                        mView.svaeSuccess();
                        ToastUtils.showShort("添加地址失败");
                    }

                    @Override
                    public void onNext(BaseResult baseResult) {
                        mView.hideProgress();
                        if (baseResult.isSuccess()) {
                            mView.svaeSuccess();
                            ToastUtils.showShort(baseResult.getMsg());
                        } else {
                            ToastUtils.showShort(baseResult.getMsg());
                        }
                    }
                });
    }

    @Override
    public void updateAddress(String userId, String ressName, String province, String city, String county, String address, String postCode, String phoneNumber, String status) {
        mModel.updateAddress(userId, ressName, province, city, county, address, postCode, phoneNumber, status)
                .subscribe(new SubscriberImpl<BaseResult>() {
                    @Override
                    public void onError(Throwable e) {
                        mView.hideProgress();
                        ToastUtils.showShort("修改地址失败");
                    }

                    @Override
                    public void onNext(BaseResult baseResult) {
                        mView.hideProgress();
                        if (baseResult.isSuccess()) {
                            mView.svaeSuccess();
                            ToastUtils.showShort(baseResult.getMsg());
                        } else {
                            ToastUtils.showShort(baseResult.getMsg());
                        }
                    }
                });
    }
}
